
# 作业一：
#while实现四种九九乘法表
# 1：while方法一
row = 1
while row <= 9:
    col = 1
    while col <= row:
        print('{}*{}={:<4}'.format(row, col, row * col), end=' ')
        col = col+1
    print('')
    row = row+1
print('-'*80)
# 2:while方法二
row = 9
while row >= 1:
    col = 1
    while col <= row:
        print('{}*{}={:<4}'.format(row, col, row * col), end=' ')
        col += 1
    print('')
    row -= 1
print('*'*80)
# 3:while方法三
row = 1
while row <= 9:
    a = 8
    while a >= row:
        print('{:<8}'.format(''),end='')
        a -= 1
    col = row
    while col >= 1:
        print('{}*{}={:<4}'.format(col,row,col*row),end='')
        col -= 1
    row += 1
    print()
print('-'*80)
# 4:while方法四
row = 9
while row > 0:
    col = 9
    while col > 0:
        if col <= row:
            print('{}*{}={:<4}'.format(col,row,col*row),end='')
        else:
            print(' '*8,end='')
        col -= 1
    row -= 1
    print()
print('*'*80)

# for……in实现九九乘法表
# 1:for……in方法一
'''
a = [1,2,3,4,5,6,7,8,9]
b = []
for row in a:
    b.append(row)
    for col in b:
        print('{}*{}={:<4}'.format(row, col, row * col), end=' ')
    print('')
'''
for row in range(1,10):
    for col in range(1,row+1):
        print('{}*{}={:<4}'.format(row,col,row*col),end=' ')
    print('')
print('-'*80)

#2:for……in方法二
for row in range(9,0,-1):
    for col in range(1,row+1):
        print('{}*{}={:<4}'.format(row,col,row*col),end=' ')
    print('')
print('*'*80)

# 3:for……in方法三
for row in range(9,0,-1):
    for col in range(1,row):
        print('{:<9}'.format(''),end='')
    for col in range(10-row,0,-1):
        print('{}*{}={:<4}'.format(row, col, col * row), end=' ')
    print()
print('-'*80)

# 4:for……in方法四
for row in range(9,0,-1):
    for col in range(9-row,0,-1):
        print('{:<9}'.format(''),end='')
    for col in range(row,0,-1):
        print('{}*{}={:<4}'.format(row, col, col * row), end=' ')
    print()
print('*'*80)